<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class JobResumeAccess extends Model
{
    const UPDATED_AT = null;
    const CREATED_AT = null;
    public $table = 'job_resume_access';

    protected $avatars = '';

    public function getBirthCnAttribute()
    {
        if (!$this->birth) {
            return "保密";
        } else {
            return (date('Y') - date('Y', strtotime($this->birth))) . "岁";
        }
    }

    public function getSexCnAttribute()
    {
        if (!$this->sex) {
            return "保密";
        } else {
            return ($this->sex == 1) ? "男" : "女";
        }
    }

    //

    /**
     * @param $params
     * @return
     */
    public static function getInformation($params)
    {
        //DB::connection()->enableQueryLog();  // 开启QueryLog
        $list = JobResumeAccess::join('resume', 'job_resume_access.resume_id', '=', 'resume.id')
            ->join('jobs', 'job_resume_access.job_id', '=', 'jobs.id')
            ->select("job_resume_access.id", "job_resume_access.status", "resume.nickname", 'job_resume_access.create_time', "resume.birth", "resume.sex", "resume.education_cn", "resume.education_cn", 'jobs.jobs_name', 'resume.wage_cn')
            ->where('job_resume_access.company_status', 1)
            ->where(function ($query) use ($params) {
                if (isSet($params['status'])) {
                    $query->where('job_resume_access.status', $params['status']);
                }
                if (isSet($params['t'])) {
                    $sec = time() - (int)$params['t'] * 24 * 3600;
                    $query->where('job_resume_access.create_time', '>', $sec);
                }
            })->paginate(10);
        //dump(DB::getQueryLog());
        return $list;

    }
}
